<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学院高基ID" prop="baseCollegeId">
        <el-input
          v-model="queryParams.baseCollegeId"
          placeholder="请输入学院高基ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学院代码" prop="orgCode">
        <el-input
          v-model="queryParams.orgCode"
          placeholder="请输入学院代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员编号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入人员编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实验室ID" prop="labId">
        <el-input
          v-model="queryParams.labId"
          placeholder="请输入实验室ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实验室编号" prop="labCode">
        <el-input
          v-model="queryParams.labCode"
          placeholder="请输入实验室编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实验室名称" prop="labName">
        <el-input
          v-model="queryParams.labName"
          placeholder="请输入实验室名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="出生年月" prop="birthday">
        <el-input
          v-model="queryParams.birthday"
          placeholder="请输入出生年月"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属学科" prop="subject">
        <el-input
          v-model="queryParams.subject"
          placeholder="请输入所属学科"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业技术职务" prop="technicalPosition">
        <el-input
          v-model="queryParams.technicalPosition"
          placeholder="请输入专业技术职务"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文化程度" prop="educationLevel">
        <el-input
          v-model="queryParams.educationLevel"
          placeholder="请输入文化程度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专家类别" prop="expertCategory">
        <el-input
          v-model="queryParams.expertCategory"
          placeholder="请输入专家类别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国内学历教育时间" prop="internalEducationTime">
        <el-input
          v-model="queryParams.internalEducationTime"
          placeholder="请输入国内学历教育时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国内非学历教育时间" prop="internalNonEducationTime">
        <el-input
          v-model="queryParams.internalNonEducationTime"
          placeholder="请输入国内非学历教育时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国外教育时间" prop="externalEducationTime">
        <el-input
          v-model="queryParams.externalEducationTime"
          placeholder="请输入国外教育时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="detailList" height="480px" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="学院高基ID" align="center" prop="baseCollegeId" /> -->
      <el-table-column label="学院名称" align="left" width="120px" prop="orgName" />
      <el-table-column label="工号" align="left" width="120px" prop="userName" />
      <!-- <el-table-column label="实验室ID" align="center" prop="labId" /> -->
      <el-table-column label="实验室房间号" align="left" width="120px" prop="roomCode" />
      <el-table-column label="实验室名称" align="left" width="120px" prop="labName" />
      <el-table-column label="姓名" align="left" width="120px" prop="name" />
      <el-table-column label="性别" align="center" :formatter="sexFormat" />
      <el-table-column label="出生年月" align="center" prop="birthday" />
      <el-table-column label="所属学科" align="center" prop="subject" />
      <el-table-column label="专业技术职务" align="center" prop="technicalPosition" />
      <el-table-column label="文化程度" align="center" prop="educationLevel" />
      <el-table-column label="专家类别" align="center" prop="expertCategory" />
      <el-table-column label="国内学历教育时间" align="center" prop="internalEducationTime" />
      <el-table-column label="国内非学历教育时间" align="center" prop="internalNonEducationTime" />
      <el-table-column label="国外教育时间" align="center" prop="externalEducationTime" />
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <!-- <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

    <!-- 添加或修改专任实验室人员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :inline=true :model="form" :rules="rules" label-width="120px" style="height: 480px; overflow: auto;">
        <!-- <el-form-item label="学院高基ID" prop="baseCollegeId">
          <el-input v-model="form.baseCollegeId" placeholder="请输入学院高基ID" />
        </el-form-item> -->
        <el-form-item label="学院名称" prop="orgCode">
          <el-input v-model="form.orgName" placeholder="请输入学院名称" disabled />
        </el-form-item>
        <el-form-item label="人员编号" prop="number">
          <el-input v-model="form.userName" placeholder="请输入人员工号" disabled />
        </el-form-item>
        <!-- <el-form-item label="实验室ID" prop="labId">
          <el-input v-model="form.labId" placeholder="请输入实验室ID" disabled />
        </el-form-item> -->
        <el-form-item label="实验室房间号" prop="labCode">
          <el-input v-model="form.roomCode" placeholder="请输入实验室房间号" disabled />
        </el-form-item>
        <el-form-item label="实验室名称" prop="labName">
          <el-input v-model="form.labName" placeholder="请输入实验室名称" disabled />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" disabled />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别" disabled >
            <el-option v-for="item in sysUserSex" :key="item.dictValue" :label="item.dictLabel" 
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生年月" prop="birthday">
          <el-input v-model="form.birthday" placeholder="请输入出生年月"  disabled />
        </el-form-item>
        <el-form-item label="所属学科" prop="subject">
          <el-input v-model="form.subject" placeholder="请输入所属学科" disabled />
        </el-form-item>
        <el-form-item label="专业技术职务" prop="technicalPosition">
          <el-input v-model="form.technicalPosition" placeholder="请输入专业技术职务" />
        </el-form-item>
        <el-form-item label="文化程度" prop="educationLevel">
          <el-input v-model="form.educationLevel" placeholder="请输入文化程度" />
        </el-form-item>
        <el-form-item label="专家类别" prop="expertCategory">
          <el-input v-model="form.expertCategory" placeholder="请输入专家类别" />
        </el-form-item>
        <el-form-item label="国内学历教育时间" prop="internalEducationTime">
          <el-input v-model="form.internalEducationTime" placeholder="请输入国内学历教育时间" />
        </el-form-item>
        <el-form-item label="国内非学历教育时间" prop="internalNonEducationTime">
          <el-input v-model="form.internalNonEducationTime" placeholder="请输入国内非学历教育时间" />
        </el-form-item>
        <el-form-item label="国外教育时间" prop="externalEducationTime">
          <el-input v-model="form.externalEducationTime" placeholder="请输入国外教育时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPerson, getPerson, delPerson, addPerson, updatePerson, exportPerson } from "@/api/statistics/statisticsPerson";

export default {
  name: "StatisticsPerson",
  props: {
    detailList: Array
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专任实验室人员表格数据
      statisticsPersonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseCollegeId: null,
        orgCode: null,
        number: null,
        labId: null,
        labCode: null,
        labName: null,
        name: null,
        sex: null,
        birthday: null,
        subject: null,
        technicalPosition: null,
        educationLevel: null,
        expertCategory: null,
        internalEducationTime: null,
        internalNonEducationTime: null,
        externalEducationTime: null,
      },
      // 表单参数
      form: {},
      sysUserSex: [],
      // 表单校验
      rules: {
        baseCollegeId: [
          { required: true, message: "学院高基ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    // sys_user_sex
    this.getDicts("sys_user_sex ").then(response => {
      this.sysUserSex = response.data;
    });
  },
  methods: {
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sysUserSex, row.sex);
    },
    /** 查询专任实验室人员列表 */
    getList() {
      this.loading = true;
      listPerson(this.queryParams).then(response => {
        this.statisticsPersonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        baseCollegeId: null,
        orgCode: null,
        number: null,
        labId: null,
        labCode: null,
        labName: null,
        name: null,
        sex: null,
        birthday: null,
        subject: null,
        technicalPosition: null,
        educationLevel: null,
        expertCategory: null,
        internalEducationTime: null,
        internalNonEducationTime: null,
        externalEducationTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加专任实验室人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPerson(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专任实验室人员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePerson(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.$emit("refresh");
            });
          } else {
            addPerson(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除专任实验室人员编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPerson(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有专任实验室人员数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPerson(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
